package edu.sju.chenshu.friend.controller.user;

import edu.sju.chenshu.common.core.constants.HttpConstants;
import edu.sju.chenshu.common.core.domain.Result;
import edu.sju.chenshu.common.core.domain.vo.LoginUserVO;
import edu.sju.chenshu.friend.domain.user.dto.UserDTO;
import edu.sju.chenshu.friend.domain.user.dto.UserUpdateDTO;
import edu.sju.chenshu.friend.domain.user.vo.UserVO;
import edu.sju.chenshu.friend.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/sendCode")
    public Result<Void> sendCode(@RequestBody UserDTO userDTO) {
        return userService.sendCode(userDTO);
    }

    @PostMapping("/code/login")
    public Result<String> codeLogin(@RequestBody UserDTO userDTO) {
        return Result.ok(userService.codeLogin(userDTO.getPhone(), userDTO.getCode()));
    }

    //接口地址 /system/sysUser/logout
    @DeleteMapping("/logout")
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return userService.logout(token);
    }

    //接口地址 /system/sysUser/info
    @GetMapping("/info")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return userService.info(token);
    }

    @GetMapping("/detail")
    public Result<UserVO> detail() {
        return Result.ok(userService.detail());
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody UserUpdateDTO userUpdateDTO) {
        return userService.edit(userUpdateDTO);
    }
}
